package com.lagou.demo.util;

import java.sql.*;

public class DBUtil {
        private static String Driver="com.mysql.jdbc.Driver";
        private static String URL="jdbc:mysql://192.168.110.128:3306/web";
        private static String root="root";
        private static String password="QiDian@666";
        private static  Connection connection=null;
        PreparedStatement ps=null;
        ResultSet resultSet=null;
        static {
            try {
                Class.forName(Driver);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        public static Connection getConnection() throws SQLException {
             connection= DriverManager.getConnection(URL, root, password);
            return connection;
        }
        public static void close(Connection connection,PreparedStatement ps){
            if(ps!=null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    public static void close(Connection connection,PreparedStatement ps,ResultSet resultSet){
        if (resultSet!=null){
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
            if(ps!=null){
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (connection!=null){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
